package com.example.blogserver.controller;

import com.example.blogserver.pojo.Article;
import com.example.blogserver.pojo.User;
import com.example.blogserver.service.ListService;
import com.example.blogserver.a_utils.ResponseBodyMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@SuppressWarnings({"all"})
@RestController
@RequestMapping("/home")
public class ListController {
    @Autowired
    private ListService listService;

    /**
     * 获取用户信息
     */
    @RequestMapping("/myMse")
    public ResponseBodyMessage<User> MyHome(HttpServletRequest request) {
        return listService.queryByAccount(request);
    }

    /**
     * 获取文章列表或是根据用户账号获取文章（获取全部文章不涉及排序规则）
     */
    @RequestMapping("/blogList")
    public ResponseBodyMessage<List<Article>> getBlogList(HttpServletRequest request) {
        return listService.getAllBlog(request);
    }

    /**
     * 根据关键字和排序规则查询文章（排序规则只针对关键字查询生效，其余查询不涉及）
     */
    @RequestMapping("/queryBlogList")
    public ResponseBodyMessage<List<Article>> queryBlogListByWord(@RequestParam String word, @RequestParam String queryRules) {
        return listService.getArticleByWord(word, queryRules);
    }

    /**
     * 根据账户查询该用户发布的文章
     */
    @RequestMapping("/myblogList")
    public ResponseBodyMessage<List<Article>> queryBlogListByAccount(HttpServletRequest request) {
        return listService.getArticlesByAccount(request);
    }

    /**
     * 一键审核列表中含有敏感词的文章
     */
    @RequestMapping("/checkByIk")
    public ResponseBodyMessage<String> checkArticlesByIk(HttpServletRequest request) {
        return listService.checkArticlesByIk(request);
    }
}
